"""
数据表模型
"""
from tortoise import Model, fields


class Dept(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100,description="部门名称")
    local = fields.CharField(max_length=100,description="办公地址")

    class Meta:
        table = "dept"
        table_description = "部门表"

class Employee(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=100,description="员工姓名")
    age = fields.IntField(description="员工年龄")
    email = fields.CharField(max_length=100,description="员工邮箱")

    # 一对多关系
    dept = fields.ForeignKeyField(
        'models.Dept',
        related_name="employees",
        on_delete=fields.CASCADE
    )
    created = fields.DatetimeField(description="注册时间",auto_now_add=True)

    class Meta:
        table = "employee"
        table_description = "员工表"